<? include"../koneksi/koneksi.php";

if(isset($tambah_pendidikan))
{
$cek=mysql_query("select count(*) as hasil from pendidikan 
				  where kd_pendidikan='$kode_pendidikan'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into pendidikan values 
				('$kode_pendidikan','$nama_pendidikan')") 
				or die ("Gagal Tambah Pendidikan");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_pendidikan&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode pendidikan Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_jabatan))
{
$cek=mysql_query("select count(*) as hasil from jabatan 
				  where kd_jabatan='$kode_jabatan'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into jabatan values 
				('$kode_jabatan','$nama_jabatan')") 
				or die ("Gagal Tambah jabatan");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_jabatan&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode jabatan Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_bagian))
{
$cek=mysql_query("select count(*) as hasil from bagian 
				  where kd_bagian='$kode_bagian'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into bagian values 
				('$kode_bagian','$nama_bagian','$divisi')") 
				or die ("Gagal Tambah Bagian");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_bagian&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode bagian Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_jobdesc))
{
$cek=mysql_query("select count(*) as hasil from jobdesc 
					where kd_kelompok='$kelompok'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into jobdesc values
				('$kode_jobdesc','$nama_jobdesc','$kelompok')") 
				or die ("Gagal Tambah jobdesc");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=jobdesc&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode seksi Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_job_kualifikasi))
{
$cek=mysql_query("select count(*) as hasil from jobdesc_kualifikasi 
					where nodet_jobdesc='$nodet_jobdesc'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into jobdesc_kualifikasi values
				('$nodet_jobdesc','$nama_kualifikasi','$kode_jobdesc','$materi')") 
				or die ("Gagal Tambah jobdesc kualifikasi");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=job_kualifikasi&kd_jobdesc=$kode_jobdesc&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode jobdesc kualifikasi Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}

elseif(isset($tambah_seksi))
{
$cek=mysql_query("select count(*) as hasil from seksi where kd_seksi='$kode_seksi'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into seksi values 
				('$kode_seksi','$nama_seksi','$bagian')") 
				or die ("Gagal Tambah seksi");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_seksi&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode seksi Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}

elseif(isset($tambah_pengalaman))
{
$cek=mysql_query("select count(*) as hasil from pengalaman where kd_pengalaman='$kode_pengalaman'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into pengalaman values 
				('','$nik','$pengalaman','$lama_pengalaman','$perusahaan')") 
				or die ("Gagal Tambah pengalaman");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=pengalaman&nik=$nik&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode pengalaman Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}

elseif(isset($tambah_divisi))
{
$cek=mysql_query("select count(*) as hasil from divisi 
				  where kd_divisi='$kode_divisi'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into divisi values 
				('$kode_divisi','$nama_divisi')") 
				or die ("Gagal Tambah divisi");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_divisi&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode bagian Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}

elseif(isset($tambah_karyawan))
{
$cek=mysql_query("select count(*) as hasil from karyawan
				  where nik='$nik'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	copy($photo,"../upload_photo/$photo_name");
	$tambah=mysql_query("insert into karyawan values 
				('$nik','$nama_karyawan','$tempat_lahir','$tanggal_lahir',
				'$jenis_kelamin','$agama','$pendidikan','$jurusan','$jabatan','$status','$tanggal_kerja'
				,'$telp','$alamat','$seksi','$photo_name')") 
				or die ("Gagal Tambah data karyawan");
				$sukses="Data Berhasil Di Input";
				header("location:index.php?act=in_karyawan&sukses=$sukses");
	
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, NIK dan Username Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}


elseif(isset($tambah_cv))
{
$cek=mysql_query("select count(*) as hasil from karyawan
				  where nik='$nik' or user_name='$user_name'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	copy($photo,"../upload_photo/$photo_name");
	$tambah=mysql_query("insert into karyawan values 
				('$nik','$nama_karyawan','$tempat_lahir','$tanggal_lahir',
				'$jenis_kelamin','$agama','$status','$telp','$alamat','$bagian','$photo_name','$user_name','$pass_word')") 
				or die ("Gagal Tambah CV");
				$sukses="Data Berhasil Di Input";
				header("location:index.php?act=in_cv&sukses=$sukses");
	
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, NIK dan Username Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_instruktur))
{
$cek=mysql_query("select count(*) as hasil from instruktur 
				  where kd_instruktur='$kode_instruktur'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into instruktur values 
				('$kode_instruktur','$nik')") 
				or die ("Gagal Tambah Bagian");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_instruktur&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode Instruktur Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_kelompok))
{
$cek=mysql_query("select count(*) as hasil from kelompok 
				  where kd_kelompok='$kode_kelompok' AND kd_pendidikan='$pendidikan' 
				  AND kd_jabatan='$jabatan' AND kd_seksi='$seksi'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into kelompok values 
				('$kode_kelompok','$nama_kelompok','$pendidikan','$jabatan','$seksi')") 
				or die ("Gagal Tambah kelompok");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_kelompok&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode kelompok Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_admin))
{
$nik=trim($nik);
$pass_word=trim($pass_word);
$cek_admin=mysql_query("select count(*) as hasil from admin
				where nik='$nik'");
$cek_admin1=mysql_fetch_row($cek_admin);
	if($cek_admin1[0]=='0')
	{
	$cek_nik=mysql_query("select count(*) as hasil from karyawan
				where nik='$nik'");
	$cek_nik1=mysql_fetch_row($cek_nik);
			if($cek_nik1[0]=='1')
			{
			$tambah=mysql_query("insert into admin values 
						('','$nik','$pass_word','$level')") 
						or die ("Gagal Tambah kelompok");
			$sukses="Data Berhasil Di Input";
			header("location:index.php?act=in_admin&sukses=$sukses");
			}
			else 
			{ 
			echo"
			<script language='javascript'>
		   alert('Maaf, NIK tidak terdaftar di data karyawan');
		   history.back(1);
		   </script>";
			exit();
			}
	}		
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, NIK sudah terdaftar di data admin');
   history.back(1);
   </script>";
	exit();
	}	 
}
elseif(isset($tambah_schedule))
{
$cek=mysql_query("select count(*) as hasil from schedule 
				  where no_schedule='$no_schedule'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into schedule values 
				('$no_schedule','$instruktur','$materi_kualifikasi','$description',
				'$tanggal','$jam')") 
				or die ("Gagal Tambah kelompok");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_schedule&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, Kode schedule Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_training))
{
$cek=mysql_query("select count(*) as hasil from training 
				  where no_training='$_POST[no_training]'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into training values 
			('$_POST[no_training]','$_POST[nama_training]','$_POST[materi_kualifikasi]','$_POST[instruktur]',
			'$_POST[tgl_mundur]','$_POST[tanggal_training]','$_POST[jam]','$_POST[jam_selesai]','$_POST[tempat]','$_POST[provider]',
			'$_POST[klasifikasi_training]',
			'$_POST[biaya]','$_POST[status_training]','$_POST[quota_peserta]','$_POST[keterangan]')") 
				or die (mysql_error().' - '."Gagal Tambah Training");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=training&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, No Training Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_karyawan_training))
{
$cek=mysql_query("select count(*) as hasil from detail_training 
				  where no_det_training='$no_det_training'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0')
	{
	$tambah=mysql_query("insert into detail_training values 
				('','$no_training','$karyawan')") 
				or die ("Gagal Tambah detail Training");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=det_training&no_training=$no_training&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, No Training Sudah Terdaftar ?');
   history.back(1);
   </script>";
	exit();
	} 
}

elseif(isset($tambah_materi))
{
	$isi_materi_name = preg_replace('/(\s)+/', '-', $isi_materi_name);
$cek=mysql_query("select count(*) as hasil from materi 
				  where kd_materi='$no_materi'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0'){
	
	$tambah=mysql_query("insert into materi values 
				('$no_materi','$nama_materi','$isi_materi_name')") 
				or die ("Gagal Tambah Training");
	$sukses="Data Berhasil Di Input";
	copy($isi_materi,"../upload_materi/$isi_materi_name");
	header("location:index.php?act=in_materi&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, No materi Sudah Terdaftar !');
   history.back(1);
   </script>";
	exit();
	} 
}
elseif(isset($tambah_buku_tamu))
{
$cek=mysql_query("select count(*) as hasil from buku_tamu 
				  where id_tamu='$id_tamu'");
$cek1=mysql_fetch_row($cek);
	if($cek1[0]=='0'){
	$tambah=mysql_query("insert into buku_tamu values 
				('$id_materi','$nama','$email','$judul','$pesan')") 
				or die ("Gagal Tambah Training");
	$sukses="Data Berhasil Di Input";
	header("location:index.php?act=in_buku_tamu&sukses=$sukses");
	}
	else 
	{ 
	echo"
	<script language='javascript'>
   alert('Maaf, No buku_tamu Sudah Terdaftar !');
   history.back(1);
   </script>";
	exit();
	} 
}

?>	
